clc; clear; close all;


%% 参数设置
% TO-GM映射参数c的范围
c_values = linspace(1.2, 1.47, 5000);
% CO-GM映射参数d的范围
d_values = linspace(1.2, 1.65, 5000);

% 预分配特征值存储
eigs_TO = zeros(length(c_values), 2);
eigs_CO = zeros(length(d_values), 2);


% 初始状态（根据论文表III）
x0_TO = 0.5; phi0_TO = -1;  % TO-GM初始条件
x0_CO = 0.5; phi0_CO = 1;   % CO-GM初始条件


% %% 迭代计算固定点
% % 计算TO-GM映射的特征值
% for i = 1:length(c_values)
%     c = c_values(i);
%     x = x0_TO; phi = phi0_TO;
% 
%     % 迭代500步达到稳态
%     for n = 1:500
%         x_new = (-1)^n + c * sin(phi) * x;
%         phi_new = 0.86*phi + 0.12*phi*abs(phi) - 0.02*phi^3 + 0.1*x;
%         x = x_new; phi = phi_new;
%     end
% 
%     % 计算雅可比矩阵
%     J11 = c * sin(phi);
%     J12 = c * x * cos(phi);
%     J21 = 0.1;
%     J22 = 0.86 + 0.12*abs(phi) + 0.12*phi*sign(phi) - 0.06*phi^2;
%     J = [J11, J12; J21, J22];
% 
%     % 存储特征值
%     eigs_TO(i,:) = eig(J);
% end
% 
% %% 计算CO-GM映射的特征值
% for i = 1:length(d_values)
%     d = d_values(i);
%     x = x0_CO; phi = phi0_CO;
% 
%     % 迭代500步达到稳态
%     for n = 1:5000
%         x_new = (-1)^n + d * cos(phi) * x;
%         phi_new = 0.1*tanh(phi^3) + 0.99*phi + 0.1*x;
%         x = x_new; phi = phi_new;
%     end
% 
%     % 计算雅可比矩阵
%     J11 = d * cos(phi);
%     J12 = -d * x * sin(phi);
%     J21 = 0.1;
%     sech_term = 1 - tanh(phi^3)^2;
%     J22 = -0.3*3*phi^2 * sech_term + 0.99;
%     J = [J11, J12; J21, J22];
% 
%     % 存储特征值
%     eigs_CO(i,:) = eig(J);
% end
% 


%% 给定固定点
% 初始状态（根据论文表IV）
k1_x  = 1.260;k1_phi= -3.263;  % TO-GM初始条件
j1_x = 1.292; j1_phi = 7.641;   % CO-GM初始条件

%% 计算TO-GM映射的特征值
for i = 1:length(c_values)
    c = c_values(i);

    % 计算雅可比矩阵
    J11 = c * sin(k1_phi);
    J12 = c * k1_x * cos(k1_phi);
    J21 = 0.1;
    J22 = 0.86 + 0.12*abs(k1_phi) + 0.12*k1_phi*sign(k1_phi) - 0.06*k1_phi^2;
    J = [J11, J12; J21, J22];

    % 存储特征值
    eigs_TO(i,:) = eig(J);
end


%% 计算CO-GM映射的特征值
for i = 1:length(d_values)
    d = d_values(i);

    % 计算雅可比矩阵
    J11 = d * cos(j1_phi);
    J12 = -d * j1_x * sin(j1_phi);
    J21 = 0.1;
    sech_term = 1 - tanh(j1_phi^3)^2;
    J22 = -0.3*3*j1_phi^2 * sech_term + 0.99;
    J = [J11, J12; J21, J22];

    % 存储特征值
    eigs_CO(i,:) = eig(J);
end


%% 绘制结果
figure;
subplot(1,2,1); hold on;
plot(real(eigs_TO), imag(eigs_TO), '+', 'MarkerSize', 1);
theta = linspace(0, 2*pi, 1000);
plot(cos(theta), sin(theta), 'k--');
axis equal; grid on;
title('(a) TO-GM (1.2-1.47)');
xlabel('实部(\lambda)'); ylabel('虚部(\lambda)');

subplot(1,2,2); hold on;
plot(real(eigs_CO), imag(eigs_CO), '*', 'MarkerSize', 1);
plot(cos(theta), sin(theta), 'k--');
axis equal; grid on;
title('(b) CO-GM (1.2-1.65)');
xlabel('实部(\lambda)'); ylabel('虚部(\lambda)');
